﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Concurrent;

namespace SharpShare.Afp.Protocol {
    public sealed class AfpPropertyCollection {
        private ConcurrentDictionary<Type, object> _values = new ConcurrentDictionary<Type, object>();

        public T Get<T>() {
            object value;
            if (!_values.TryGetValue(typeof(T), out value)) {
                return default(T);
            }
            return (T)value;
        }
        public T GetOrSet<T>() where T : new() {
            object value = _values.GetOrAdd(typeof(T), t => {
                return new T();
            });

            return (T)value;
        }
        public void Set<T>(T value) {
            _values[typeof(T)] = value;
        }
    }
}
